#ifndef __VECTORTIMER__
#define __VECTORTIMER__

#include "Raknet\RakPeerInterface.h"
#include <hash_map>
#include <vector>
#include "Common.h"
#include "HelperClass.h"
#include "Common.h"
#include <string>

using  RakNet::RakNetGUID;
using std::vector;
using std::hash_map;


class VectorTimer
{
public:
	virtual void FromString();
	virtual std::string ToString();
};

//template<typename T>
//class ExpandableVectorTimer
//{
//public:
//	T updateRepresented;
//	hash_map<std::string, int> vectorTimer;
//};

/*
	FixedVectorTimer 
	parsed string output => update-index-timers;
*/
template<typename T>
class FixedVectorTimer
{
public:
	bool initOnly;
	T updateRepresented;
	vector<int> vectorTimer;
	int index;

	FixedVectorTimer()
	{

	}

	FixedVectorTimer(int& _index)
	{
		vectorTimer = vector<int>(FIXED_AMOUNT_PEERS);
		index = _index;

		for (int index = 0; index < FIXED_AMOUNT_PEERS; index ++)
		{
			vectorTimer[index] = 0;
		}
		updateRepresented = T(" ");
	}

	FixedVectorTimer(std::string& stringInt)
	{
		vectorTimer = vector<int>(FIXED_AMOUNT_PEERS);
		index = std::stoi(stringInt);
		updateRepresented = T(" ");
	}

	T& GetValue()
	{
		return updateRepresented;
	}

	void AddToTimer(int index, int timerValue)
	{
		if (index > 0 && index < vectorTimer.size())
		{
			vectorTimer[index] = timerValue;
		}
	}

	void UpdatePeerTimer(int p_timerValue)
	{
		vectorTimer[index] = p_timerValue;
	}

	//using VectorTimer::ToString;
	std::string ToString()
	{
		std::string output = "";
		output = output + (updateRepresented+"-");
		for (int index = 0; index < vectorTimer.size(); index ++)
		{
			output += std::to_string(vectorTimer[index]) + (index == vectorTimer.size() - 1 ? ";":",");
		}

		return output;
	}

	//using VectorTimer::FromString;
	void FromString(std::string input)
	{
		std::string stringArray[2];
		HelperClass::ParseStringSentence(input, "-", stringArray);

		std::string timerInput[FIXED_AMOUNT_PEERS];
		HelperClass::ParseStringSentence(stringArray[1], ",", timerInput);
		
		vectorTimer = vector<int>();

		for (int index = 0; index < FIXED_AMOUNT_PEERS; index ++)
		{

			if (timerInput[index].empty())
			{
				vectorTimer.push_back(0);
			}
			else
			{
				vectorTimer.push_back(std::stoi(timerInput[index].c_str()));
			}
			
		}

		updateRepresented = T(stringArray[0]);
	}

	void SetUpdatedVersion(T _updateRepresented)
	{
		updateRepresented = _updateRepresented;
	}

	void SetIndex(int _index)
	{
		index = _index;
	}
};

#endif // !
